package com.fliad.ai.controller;

import com.fliad.ai.dto.taskmodel.*;
import com.fliad.ai.service.TaskService;
import org.noear.snack.ONode;
import org.noear.solon.annotation.*;
import org.noear.solon.core.handle.Context;

import java.io.IOException;

@Controller
public class TaskController {

    @Inject
    TaskService taskService;

    @Post
    @Mapping("/run")
    public TaskRunOutput taskRun(Context ctx) throws IOException {
        TaskRunInput request = ONode.deserialize(ctx.body(), TaskRunInput.class);
        return taskService.taskRun(request);
    }

    @Get
    @Mapping("/report")
    public TaskReportOutput taskReport(String taskId) throws IOException {
        return taskService.taskReport(new TaskReportInput(taskId));
    }

    @Mapping("/result")
    public TaskResultOutput taskResult(Context ctx) throws IOException {
        return taskService.taskResult(new TaskResultInput(ctx.param("taskId")));
    }

    @Put
    @Mapping("/cancel")
    public TaskCancelOutput taskCancel(Context ctx) throws IOException {
        TaskCancelInput request = ONode.deserialize(ctx.body(), TaskCancelInput.class);
        return taskService.taskCancel(request);
    }

}
